﻿using System.Windows;

namespace Efm.Progress
{
    /// <summary>
    /// Interaction logic for WinProgress.xaml
    /// </summary>
    internal partial class WinProgress
    {
        private readonly ProgressBox _progress;


        public WinProgress(ProgressBox progress)
        {
            InitializeComponent();

            _progress = progress;

            for (var i = 0; i < _progress.Count; i++)
                ProgressData.Children.Add(_progress[i]);

            Loaded += WinProgress_Loaded;



        }

        void WinProgress_Loaded(object sender, RoutedEventArgs e)
        {
            ContentText.Text = _progress.Text;

            if (!_progress.ShowCancelButton) CancelButton.Visibility = Visibility.Collapsed;
            if (!_progress.ShowPauseButton) PauseButton.Visibility = Visibility.Collapsed;
            if (string.IsNullOrEmpty(ContentText.Text)) ContentText.Visibility = Visibility.Collapsed;
            if (!_progress.ShowCancelButton && !_progress.ShowPauseButton) ButtonControl.Visibility = Visibility.Collapsed;


        }


        private void Cancel_Click(object sender, RoutedEventArgs e)
        {
            _progress.Cancel();
        }

        private void Pause_Click(object sender, RoutedEventArgs e)

        {
            _progress.Pause();
        }

        public void SetTextButton()
        {
            PauseButton.Content = _progress.IsPaused ? "Continue" : "Pause";
        }

        
    }

}
